﻿#ifndef __SS_THREAD_LOCK_H__
#define __SS_THREAD_LOCK_H__

#ifdef SS_USE_BOOST_THREAD
#include <boost/thread.hpp>
#elif defined _WIN32
#include <Windows.h>
#else
#include <pthread.h>
#endif
#include "ssAtomic.h"

namespace StarSeeker
{
#ifdef SS_USE_BOOST_THREAD
	typedef boost::mutex::scoped_lock	ssBoostLock;
	typedef boost::mutex				ssBoostMutex;
#endif

class ssThreadLock
{
public:
	ssThreadLock(void);
	~ssThreadLock(void);

	void Lock();

	void Unlock();

	bool IsLocked();

	long GetRef();

private:
	ssAtomicl			m_reference;
public:
#ifdef SS_USE_BOOST_THREAD
	ssBoostMutex		m_mutex;
#elif defined _WIN32
	CRITICAL_SECTION	m_mutex;
#else
    pthread_mutex_t     m_mutex;
#endif
};


#define SS_MUTEX_LOCK(lk)	lk.Lock();
#define SS_MUTEX_UNLOCK(lk)	lk.Unlock();


}
#endif
